package com.ningmengs789.live.video.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ningmengs789.live.R;
import com.ningmengs789.live.net.response.SMDLResponse;
import com.ningmengs789.live.server.widget.SelectableRoundedImageView;
import com.ningmengs789.live.utils.CommonUtils;
import com.bumptech.xchat.Glide;

public class ItemMyVideoHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    private SelectableRoundedImageView mIcon;
    private TextView mLikeNum;

    private MyVideoAdapter.MyItemClickListener mItemClickListener;

    public ItemMyVideoHolder (View itemView, MyVideoAdapter.MyItemClickListener mItemClickListener) {
        super(itemView);

        mIcon =  itemView.findViewById(R.id.lvi2_icon);
        mLikeNum =  itemView.findViewById(R.id.lvi2_praise_tv);

        this.mItemClickListener = mItemClickListener;
        itemView.findViewById(R.id.lvi2_del).setOnClickListener(this);
        mIcon.setOnClickListener(this);
    }

    public void bind(SMDLResponse.ListBean bean, int width) {

        mLikeNum.setText(bean.getLike_num() + "");

        ViewGroup.LayoutParams params = mIcon.getLayoutParams();
        params.width = width;
        params.height = (int)(width*1.5);
        mIcon.setLayoutParams(params);

        Glide.with(itemView.getContext())
                .load(CommonUtils.getUrl(bean.getVideo_cover_img()))
                .into(mIcon);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.lvi2_del:
                mItemClickListener.onItemDelete(v, getLayoutPosition());
                break;
            case R.id.lvi2_icon:
                mItemClickListener.onItemOpen(v, getLayoutPosition());
                break;
        }
    }
}
